package com.mi.global.shop;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;



import com.mi.global.shop.R;
import com.mi.global.shop.common.utils.CustomNotificationUtil;
import com.mi.global.shop.common.utils.NotificationUtil;
import com.xiaomi.mipush.sdk.MiPushClient;


public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        findViewById(R.id.btn_style1).setOnClickListener(this);
        findViewById(R.id.btn_style2).setOnClickListener(this);
        findViewById(R.id.btn_style3).setOnClickListener(this);
        findViewById(R.id.btn_style4).setOnClickListener(this);

        initMiPush();
    }

    private static final String APP_ID_PUSH = "2882303761517345102";
    private static final String APP_TOKEN_PUSH = "5181734554102";
    private void initMiPush() {
        MiPushClient.registerPush(this, APP_ID_PUSH, APP_TOKEN_PUSH);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_style1: {
                CustomNotificationUtil.handleCustomNotificationContent(this, getContent1());
                break;
            }
            case R.id.btn_style2: {
                CustomNotificationUtil.handleCustomNotificationContent(this, getContent2());
                break;
            }
            case R.id.btn_style3: {
                CustomNotificationUtil.handleCustomNotificationContent(this, getContent3());
                break;
            }
            case R.id.btn_style4: {
//                CustomNotificationUtil.handleCustomNotificationContent(this, getContent4());
                NotificationUtil.sendNotification(getApplicationContext(), R.drawable.icon_logo, "标题", "哈哈哈哈", null);
                break;
            }

        }
    }

    private String getContent1() {
        return "{\"title\":\"\\u6807\\u9898\",\"url\":\"http:\\/\\/www.baidu.com\\/?efe=push2K2vG9\",\"icon_url\":\"http:\\/\\/res.ittianyu.com\\/mi_logo.png\",\"data\":[{\"content\":\"\\u63cf\\u8ff01\",\"type\":0},{\"content\":\"\\u63cf\\u8ff02\",\"type\":0}]}";
    }

    private String getContent2() {
        return "{\n" +
                "    \"title\": \"我是标题\",\n" +
                "    \"url\": \"https://www.mi.com/\",\n" +
                "    \"data\": [\n" +
                "        {\"type\": 1, content: \"http://res.ittianyu.com/mi_image.jpeg\"}\n" +
                "    ],\n" +
                "    \"icon_url\": \"http://res.ittianyu.com/mi_logo.png\"\n" +
                "}";
    }

    private String getContent3() {
        return "{\n" +
                "    \"title\": \"我是标题\",\n" +
                "    \"url\": \"https://www.mi.com/\",\n" +
                "    \"data\": [\n" +
                "        {\"type\": 0, content: \"第一行特别长长长长长长长长长长长长长长长长长长长长长长长长长长长长长\"},\n" +
                "        {\"type\": 1, content: \"http://res.ittianyu.com/mi_image.jpeg\"}\n" +
                "    ],\n" +
                "    \"icon_url\": \"http://res.ittianyu.com/mi_logo.png\"\n" +
                "}";
    }

    private String getContent4() {
        return "{\n" +
                "    \"title\": \"我是标题\",\n" +
                "    \"url\": \"https://www.mi.com/\",\n" +
                "    \"type_id\": \"1\",\n" +
                "    \"type\": 3, // multiTextAndSmallImage\n" +
                "    \"content\": \"多行文本\n2\n3\",\n" +
                "    \"icon_url\": \"http://res.ittianyu.com/mi_logo.png\",\n" +
                "    \"image_url\": \"http://res.ittianyu.com/mi_image.jpeg\"\n" +
                "}";
    }

}

/*
{
    "title": "我是标题",
    "url": "https://www.mi.com/",
    "data": [
        {"type": 0, content: "第一行特别长长长长长长长长长长长长长长长长长长长长长长长长长长长长长"},
        {"type": 0, content: "第2行22222222"}
    ],
    "icon_url": "http://res.ittianyu.com/mi_logo.png"
}

{
    "title": "我是标题",
    "url": "https://www.mi.com/",
    "data": [
        {"type": 1, content: "http://res.ittianyu.com/mi_image.jpeg"}
    ],
    "icon_url": "http://res.ittianyu.com/mi_logo.png"
}

{
    "title": "我是标题",
    "url": "https://www.mi.com/",
    "data": [
        {"type": 0, content: "第一行特别长长长长长长长长长长长长长长长长长长长长长长长长长长长长长"},
        {"type": 1, content: "http://res.ittianyu.com/mi_image.jpeg"}
    ],
    "icon_url": "http://res.ittianyu.com/mi_logo.png"
}

{
    "title": "我是标题",
    "url": "https://www.mi.com/",
    "type_id": "1",
    "type": 0, // multiTextAndSmallImage
    "content": "多行文本\n2\n3",
    "icon_url": "http://res.ittianyu.com/mi_logo.png",
    "image_url": "http://res.ittianyu.com/mi_image.jpeg"
}
 */